package com.eova.cloud;

import com.eova.cloud.auth.EovaApp;
import com.eova.common.utils.xx;

public class AuthCloud {
	public static void init(){
		System.out.println("override init !!!");
	}
	
	public static String publicKey = "xxxx+a21jY5whyVZYJmsiIZwWW8efAYJH9nEHRqtJI5bdcu5SkZqDOwGBu24bcd1aRSo/bbd+fgStIcSYf+tnmyZfwhoxjUhQSnL+w60mYAq2sRypCPtHsZsGIbsdUmWJhnpuj0CJ/bdfc";

	private static EovaApp app;

	/**
	 * @param appId
	 * @param appSecret
	 * @return
	 */
	public static boolean isAuthApp(String appId, String appSecret) {
		return true;
		//return getEovaApp().isAuth();
	}

	//TODO:权许可证干掉
	public static EovaApp getEovaApp() {
		try {
			if (app != null) {
				return app;
			}
			app = new EovaApp();
			String appId = xx.getConfig("app_id").trim();
			String appSecret = xx.getConfig("app_secret").trim();
//			byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPublicKeyByStr(publicKey), Base64.decode(appSecret));
//			String s = new String(res, "UTF-8");
//			String[] ss = s.split(",");
//			app.setId(appId);
//			app.setSecret(appSecret.replace("©", "&copy;"));
//			app.setDomain(xx.getConfig("app_domain"));
//			app.setLogo(xx.getConfig("app_logo"));
//			app.setName(ss[1]);						//xm-test（从eova授权中心获取）
//			app.setCopyright(ss[2]);				//Powered by EOVA V1.6 © 2013-2017（从eova授权中心获取）
//			if (appId.equalsIgnoreCase(ss[0])) {	//eova5054857007888185（从eova授权中心获取 和 本地中对比验证）
				app.setAuth(true);
//			}
		} catch (Exception e) {
			//LogKit.info("应用ID和应用密钥在http://www.eova.cn/app 免费注册获取,Eova app config error：" + e.getMessage());
			//e.printStackTrace();
		}finally {
			app = new EovaApp();
			app.setDomain("https://niuxx.top");
			app.setLogo("/eova/ui/images/logo.png");							//无用，前段根据端口匹配
			app.setCopyright("Powered by nxx V1.6 © 2015-2021 for [s]");//无用，前段根据端口匹配
			//app.setId(System.getProperty("serverPort"));
			String xm_cmp_name = "xm_cmp_name";
			app.setName(xm_cmp_name);
			app.setAuth(true);
			return app;
		}
	}
}